﻿using System;
using Eve.TapToClick.Core.Control;
using Eve.TapToClick.Models;

namespace Eve.TapToClick.Core.Control
{
    class Control2 : MainControl
    {

        public Control2(AppConfiguration appConfiguration, MouseButtonCase mouseButtonCase) : base(appConfiguration, mouseButtonCase, 2)
        {
        }

        public override void First()
        {
        }

        public override void Last()
        {
            // 两个触碰点点击，打开鼠标右键菜单栏
            if(SingleClick())
            {
                mouseButtonCase.SendRightClick();
            }
        }

        public override void Sustained()
        {
            uint x1 = XValues[0], y1 = YValues[0];
            uint x2 = XValues[1], y2 = YValues[1];

            int XDiff = 0, YDiff = 0;

            if (x1 > x2)
            {
                // x轴向左
                XDiff = -(int)(x1 - x2);
            }
            else if (x1 < x2)
            {
                // x轴向右
                XDiff = (int)(x2 - x1);
            }

            if (y1 > y2)
            {
                // y轴向上
                YDiff = -(int)(y1 - y2);
            }
            else if (y1 < y2)
            {
                // y轴向下
                YDiff = (int)(y2 - y1);
            }

            uint UXDiff = (uint)XDiff, UYDiff = (uint)YDiff;
            XDiff = (int)(XDiff * appConfiguration.WheeSpeed);
            YDiff = (int)(YDiff * appConfiguration.WheeSpeed);

            if ((XDiff != 0 || YDiff != 0) && !SingleClick())
            {
                if (UXDiff < UYDiff)
                {
                    if (UYDiff > appConfiguration.MinWheelDiff)
                    {
                        mouseButtonCase.SendYWheel(YDiff);
                    }
                }
                else
                {
                    if (UXDiff > appConfiguration.MinWheelDiff)
                    {
                        mouseButtonCase.SendXWheel(XDiff);

                    }
                }
            }
        }
    }
}
